﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace ZC.MUSIC.COMMAND
{

    public class CheckPwdCommand<T> :ICommand
    {
        private Action<T> _excute;
        private Func<T, bool> _canExcute;

        public CheckPwdCommand(Action<T> excute)
            :this(excute,null)
        {

        }
        public CheckPwdCommand(Action<T> excute,Func<T,bool> canExcute)
        {
            if(excute!= null)
            {
                _excute = excute;
            }
            if(canExcute != null)
            {
                _canExcute = canExcute;
            }
        }


        public event EventHandler CanExecuteChanged;

        public bool CanExecute(object parameter)
        {
            return _canExcute == null ? true : _canExcute((T)parameter);
        }

        public void Execute(object parameter)
        {
            _excute?.Invoke((T)parameter);
        }
    }
}
